//
//  CaseWashCollectionLayout.m
//  WashForU
//
//  Created by 王俊 on 15/11/26.
//  Copyright © 2015年 王俊. All rights reserved.
//

#import "CaseWashCollectionLayout.h"

@implementation CaseWashCollectionLayout

- (BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
{
    return true;
}

- (void)prepareLayout
{
    [super prepareLayout];
}

- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    UICollectionViewLayoutAttributes *attribute = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
    attribute.frame = CGRectMake(((int)indexPath.row % (int)COLUMNCOUNT)*COLUMNMARGIN + COLUMNMARGIN + ((int)indexPath.row % (int)COLUMNCOUNT)*ITEMWIDTH + 5,(indexPath.row / (int)COLUMNCOUNT) * (ITEMHEIGHT + ROWMARGIN) + 5,ITEMWIDTH,ITEMHEIGHT);
    return attribute;

    
}
- (nullable NSArray<__kindof UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect
{
    NSMutableArray *attributes = [[NSMutableArray alloc]init];
    for (int i = 0; i < ITEMNUMBER ; i++ ) {
        NSIndexPath *index = [NSIndexPath indexPathForItem:i  inSection:0];
        UICollectionViewLayoutAttributes *attribute = [self layoutAttributesForItemAtIndexPath:index];
        [attributes addObject:attribute];
    }
    return attributes;
    
}

- (CGSize)collectionViewContentSize
{
    CGFloat contentHeight = ((int)ITEMNUMBER / (int)COLUMNCOUNT)*(ITEMHEIGHT + ROWMARGIN);
    return CGSizeMake(SCREENWIDTH, contentHeight);
}


@end

